Generate: FLAX infers pad token in its absence and has functional example#21009
Merged
gante merged 2 commits intohuggingface:mainfrom Jan 5, 2023
Merged
Generate: FLAX infers pad token in its absence and has functional example#21009gante merged 2 commits intohuggingface:mainfrom
gante merged 2 commits intohuggingface:mainfrom
Conversation
gante
commented
Jan 4, 2023
Comment on lines
+705
to
+709
| eos_token_id = generation_config.eos_token_id | ||
| if isinstance(eos_token_id, list): | ||
| eos_token_id = eos_token_id[0] | ||
| logger.warning(f"Setting `pad_token_id` to `eos_token_id`:{eos_token_id} for open-end generation.") | ||
| generation_config.pad_token_id = eos_token_id |
Contributor
Author
There was a problem hiding this comment.
Took the opportunity also to copy the logic to TF, so it can also handle eos_token_id as a list 👀
|
The documentation is not available anymore as the PR was closed or merged. |
4 tasks
Contributor
sanchit-gandhi
left a comment
There was a problem hiding this comment.
Thanks for the fix @gante!
silverriver
pushed a commit
to silverriver/transformers
that referenced
this pull request
Jan 6, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Some bug fixing in advance of #21007 (PR that adds generation config to Flax), to ensure we start from a functional flax generate codebase.
In particular:
pad_token_idwhen it isNoneandeos_token_idis notNone, like TF and PT do. This is very helpful for open text generation examples, like with GPT2, was an open request (Generating with Flax fails when using Causal Language models #18884), and was one of the causes for failure in the existing example. This also includes the recent changes of Add custom stop token ids for generation #20727, whereeos_token_idcan be a list of tokens.int32type specification was missing in the special tokens -- when converted to JAX variables, JAX assumed they werefloat32;